package com.songsong.myblog2.controller;


import com.songsong.myblog2.service.ArticleService;
import com.songsong.myblog2.service.CategoriesService;
import com.songsong.myblog2.service.TagService;
import com.songsong.myblog2.service.UserService;
import com.songsong.myblog2.util.TransCodingUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 控制主页面所有的页面跳转
 */
@Controller
@RequestMapping("/main")
public class MainControl {
    /*注入articleService*/
    @Resource(name = "articleService")
    private ArticleService articleService;
    /*注入tagService*/
    @Resource(name = "tagService")
    private TagService tagService;
    //注入Categories
    @Resource(name = "categoriesService")
    private CategoriesService categoriesService;
    //注入用户services
    @Autowired
    private UserService userService;
    /**
     * 获得标签云
     */
    @GetMapping("/findTagsCloud")
    @ResponseBody
    public JSONObject findTagsCloud() {
        JSONObject tagsCloud = tagService.findTagsCloud();
        return tagsCloud;
    }

    /*
     * 获取网站信息
     * */
    @GetMapping("/getSiteInfo")
    @ResponseBody
    public JSONObject getSiteInfo() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("articleNum", articleService.getArticleNum());
        jsonObject.put("tagsNum", tagService.getTagNum());
        jsonObject.put("categoriesNum", categoriesService.getCategoriesNum());
        jsonObject.put("userNum", userService.getUserNum());
        return jsonObject;
    }

    /**
     * 获得最新文章
     */
    @GetMapping("/newArticle")
    @ResponseBody
    public JSONObject newComment(@RequestParam("rows") String rows,
                                 @RequestParam("pageNum") String pageNum) {

        return articleService.findFiveNewArticle(Integer.parseInt(rows), Integer.parseInt(pageNum));
    }

    /**
     * 获得最热文章
     */
    @GetMapping("/hotArticle")
    @ResponseBody
    public JSONObject hotComment(@RequestParam("rows") String rows,
                                 @RequestParam("pageNum") String pageNum) {

        return articleService.findFiveHotArticle(Integer.parseInt(rows), Integer.parseInt(pageNum));
    }

    /*跳转到我的故事页面*/
    @RequestMapping("/mystory")
    public String mystory() {
        /*返回到我的故事页面*/
        return "anon/mystory";
    }

    /*跳转友链页面*/
    @RequestMapping("/toFriendlyLink")
    public String toFriendlyLink() {
        /*返回到友链页面*/
        return "anon/friendlylink";
    }

    /*跳转关于我页面*/
    @RequestMapping("/toAboutMe")
    public String toAboutMe() {
        /*返回到关于我页面*/
        return "anon/aboutme";
    }

    /*跳转到我的女孩页面*/
    @RequestMapping("/mylove")
    public String mylove() {
        /*返回到我的故事页面*/
        return "anon/mylove";
    }

    /*跳转到3D相册*/
    @RequestMapping("/photo3D")
    public String photo3D() {
        /*返回到我的故事页面*/
        return "love/3d/photo3D";
    }
}
